capture log close
clear all
macro drop _all
set more off
set scheme s1mono
pause on

use study2_deidentified.dta, clear

// Party identification:
gen dem_pid7=.
replace dem_pid7=0 if dem_partyid!=.
replace dem_pid7=1 if dem_lean==2
replace dem_pid7=2 if dem_partyid==2
replace dem_pid7=3 if dem_strongd==1
replace dem_pid7=-1 if dem_lean==1
replace dem_pid7=-2 if dem_partyid==1
replace dem_pid7=-3 if dem_strongr==1
label var dem_pid7 "Party ID 7 (-3=SR, 3=SD)"


// Subset to white folks only 
drop if dem_racewhite != 1

// Eliminate people who stop answering fairness evaluations less than 75% into the survey
bysort pid: egen obs_fairness=count(offer_fairness)
drop if obs_fairness==0

gen r=round if skip_fairness~=.
bysort pid: egen maxround=max(r)
preserve
	collapse (first) obs_fairness (first) maxround, by(pid)
	tab obs_fairness maxround
	count if maxround<=41*.75
	drop if maxround<=41*.75
	tab obs_fairness maxround
restore
drop if maxround<=41*.75
drop maxround obs_fairness

// Keep only black/white interactions
drop if proposer_race == 2 | responder_race == 2

* Labels
label var symbolic_binary "Racial Resentment Indicator (1 = RR > 0.5, 0 = else)"
label var overt_binary "Explicit Prejudice Indicator (1 = EP > 0, 0 = else)"
label var offer_fairness "Perceived Offer Fairness (0-100)"

* Indicators for race pair types (randomly assigned treatments) *
gen T_bP_bR = round_racepair == 1
gen T_bP_wR = round_racepair == 3
gen T_wP_wR = round_racepair == 9
gen T_wP_bR = round_racepair == 7
label var T_bP_bR "Black Proposer to Black Responder (BB - WW)"
label var T_bP_wR "Black Proposer to White Responder (BW - WW)"
label var T_wP_wR "White Proposer to White Responder (WW)"
label var T_wP_bR "White Proposer to Black Responder (WB - WW)"

// Generate indicators w/ Racial Resentment binary
gen R_symbolbinary_ww = symbolic_binary * T_wP_wR
gen R_symbolbinary_wb = symbolic_binary * T_wP_bR
gen R_symbolbinary_bb = symbolic_binary * T_bP_bR
gen R_symbolbinary_bw = symbolic_binary * T_bP_wR
label var R_symbolbinary_ww "Racial Resentment x White-White Pair (WW)"
label var R_symbolbinary_wb "Racial Resentment x White-Black Pair (WB - WW)"
label var R_symbolbinary_bb "Racial Resentment x Black-Black Pair (BB - WW)"
label var R_symbolbinary_bw "Racial Resentment x Black-White Pair (BW - WW)"

// Generate indicators w/ Explicit binary
gen R_Explicitbinary_ww = overt_binary * T_wP_wR
gen R_Explicitbinary_wb = overt_binary * T_wP_bR
gen R_Explicitbinary_bb = overt_binary * T_bP_bR
gen R_Explicitbinary_bw = overt_binary * T_bP_wR
label var R_Explicitbinary_ww "Explicit Prejudice x White-White Pair (WW)"
label var R_Explicitbinary_wb "Explicit Prejudice x White-Black Pair (WB - WW)"
label var R_Explicitbinary_bb "Explicit Prejudice x Black-Black Pair (BB - WW)"
label var R_Explicitbinary_bw "Explicit Prejudice x Black-White Pair (BW - WW)"

egen numobs=count(offer_fairness), by(pid)

* TableS2.1, main analysis, eliminating those who failed both screeners

preserve

drop if failtwo == 1

regress offer_fairness T_bP_wR T_wP_bR T_bP_bR i.offer_amount i.round,	robust cluster(pid)

//BW - WB difference: 
lincom T_bP_wR - T_wP_bR
local ingroupdiff = r(estimate)
local ingroupdiffse = r(se)

outreg using output/TableS2.1_Study2_Fairness.out, se bracket rdec(3) adec(3)3aster addstat("Ingroup Difference (BW - WB)", `ingroupdiff', "Ingroup Difference SE (BW - WB)", `ingroupdiffse') addnote("OLS coefficients with robust standard errors in brackets, clustered at respondent level.") replace

regress offer_fairness T_bP_wR T_wP_bR T_bP_bR R_symbolbinary_bw R_symbolbinary_wb R_symbolbinary_bb symbolic_binary i.offer_amount i.round, robust cluster(pid)

// BW - WB differences
lincom T_bP_wR - T_wP_bR
local ingroupdiff = r(estimate)
local ingroupdiffse = r(se)
lincom R_symbolbinary_bw - R_symbolbinary_wb
local rringroupdiff = r(estimate)
local rringroupdiffse = r(se)

outreg using output/TableS2.1_Study2_Fairness.out, se bracket rdec(3) adec(3)3aster addstat("Ingroup Difference (BW - WB)", `ingroupdiff', "Ingroup Difference SE (BW - WB)", `ingroupdiffse',"Racial Resentment x Ingroup Difference (BW - WB)", `rringroupdiff', "Racial Resentment x Ingroup Difference SE (BW - WB)", `rringroupdiffse') append

regress offer_fairness T_bP_wR T_wP_bR T_bP_bR R_Explicitbinary_bw R_Explicitbinary_wb R_Explicitbinary_bb overt_binary i.offer_amount i.round, robust cluster(pid)

// BW - WB differences
lincom T_bP_wR - T_wP_bR
local ingroupdiff = r(estimate)
local ingroupdiffse = r(se)
lincom R_Explicitbinary_bw - R_Explicitbinary_wb
local epingroupdiff = r(estimate)
local epingroupdiffse = r(se)

outreg using output/TableS2.1_Study2_Fairness.out, se bracket rdec(3) adec(3)3aster addstat("Ingroup Difference (BW - WB)", `ingroupdiff', "Ingroup Difference SE (BW - WB)", `ingroupdiffse',"Explicit Prejudice x Ingroup Difference (BW - WB)", `epingroupdiff', "Explicit Prejudice x Ingroup Difference SE (BW - WB)", `epingroupdiffse') append

regress offer_fairness T_bP_wR T_wP_bR T_bP_bR R_symbolbinary_bw R_symbolbinary_wb R_symbolbinary_bb R_Explicitbinary_bw R_Explicitbinary_wb R_Explicitbinary_bb symbolic_binary overt_binary i.offer_amount i.round, robust cluster(pid)

// BW - WB differences
lincom T_bP_wR - T_wP_bR
local ingroupdiff = r(estimate)
local ingroupdiffse = r(se)
lincom R_symbolbinary_bw - R_symbolbinary_wb
local rringroupdiff = r(estimate)
local rringroupdiffse = r(se)
lincom R_Explicitbinary_bw - R_Explicitbinary_wb
local epingroupdiff = r(estimate)
local epingroupdiffse = r(se)
	
outreg using output/TableS2.1_Study2_Fairness.out, se bracket rdec(3) adec(3)3aster addstat("Ingroup Difference (BW - WB)", `ingroupdiff', "Ingroup Difference SE (BW - WB)", `ingroupdiffse', "Racial Resentment x Ingroup Difference (BW - WB)", `rringroupdiff', "Racial Resentment x Ingroup Difference SE (BW - WB)", `rringroupdiffse', "Explicit Prejudice x Ingroup Difference (BW - WB)", `epingroupdiff', "Explicit Prejudice x Ingroup Difference SE (BW - WB)", `epingroupdiffse') append

restore

* TableS2.2, restricting to those who answered all evaluations and passed screener

preserve

drop if failtwo == 1
drop if numobs~=36

regress offer_fairness T_bP_wR T_wP_bR T_bP_bR i.offer_amount i.round,	robust cluster(pid)

//BW - WB difference: 
lincom T_bP_wR - T_wP_bR
local ingroupdiff = r(estimate)
local ingroupdiffse = r(se)

outreg using output/TableS2.2_Study2_Fairness_PerformedAllEvals.out, se bracket rdec(3) adec(3)3aster addstat("Ingroup Difference (BW - WB)", `ingroupdiff', "Ingroup Difference SE (BW - WB)", `ingroupdiffse') addnote("OLS coefficients with robust standard errors in brackets, clustered at respondent level.") replace

regress offer_fairness T_bP_wR T_wP_bR T_bP_bR R_symbolbinary_bw R_symbolbinary_wb R_symbolbinary_bb symbolic_binary i.offer_amount i.round, robust cluster(pid)

// BW - WB differences
lincom T_bP_wR - T_wP_bR
local ingroupdiff = r(estimate)
local ingroupdiffse = r(se)
lincom R_symbolbinary_bw - R_symbolbinary_wb
local rringroupdiff = r(estimate)
local rringroupdiffse = r(se)

outreg using output/TableS2.2_Study2_Fairness_PerformedAllEvals.out, se bracket rdec(3) adec(3)3aster addstat("Ingroup Difference (BW - WB)", `ingroupdiff', "Ingroup Difference SE (BW - WB)", `ingroupdiffse',"Racial Resentment x Ingroup Difference (BW - WB)", `rringroupdiff', "Racial Resentment x Ingroup Difference SE (BW - WB)", `rringroupdiffse') append

regress offer_fairness T_bP_wR T_wP_bR T_bP_bR R_Explicitbinary_bw R_Explicitbinary_wb R_Explicitbinary_bb overt_binary i.offer_amount i.round, robust cluster(pid)

// BW - WB differences
lincom T_bP_wR - T_wP_bR
local ingroupdiff = r(estimate)
local ingroupdiffse = r(se)
lincom R_Explicitbinary_bw - R_Explicitbinary_wb
local epingroupdiff = r(estimate)
local epingroupdiffse = r(se)

outreg using output/TableS2.2_Study2_Fairness_PerformedAllEvals.out, se bracket rdec(3) adec(3)3aster addstat("Ingroup Difference (BW - WB)", `ingroupdiff', "Ingroup Difference SE (BW - WB)", `ingroupdiffse',"Explicit Prejudice x Ingroup Difference (BW - WB)", `epingroupdiff', "Explicit Prejudice x Ingroup Difference SE (BW - WB)", `epingroupdiffse') append

regress offer_fairness T_bP_wR T_wP_bR T_bP_bR R_symbolbinary_bw R_symbolbinary_wb R_symbolbinary_bb R_Explicitbinary_bw R_Explicitbinary_wb R_Explicitbinary_bb symbolic_binary overt_binary i.offer_amount i.round, robust cluster(pid)

// BW - WB differences
lincom T_bP_wR - T_wP_bR
local ingroupdiff = r(estimate)
local ingroupdiffse = r(se)
lincom R_symbolbinary_bw - R_symbolbinary_wb
local rringroupdiff = r(estimate)
local rringroupdiffse = r(se)
lincom R_Explicitbinary_bw - R_Explicitbinary_wb
local epingroupdiff = r(estimate)
local epingroupdiffse = r(se)
	
outreg using output/TableS2.2_Study2_Fairness_PerformedAllEvals.out, se bracket rdec(3) adec(3)3aster addstat("Ingroup Difference (BW - WB)", `ingroupdiff', "Ingroup Difference SE (BW - WB)", `ingroupdiffse', "Racial Resentment x Ingroup Difference (BW - WB)", `rringroupdiff', "Racial Resentment x Ingroup Difference SE (BW - WB)", `rringroupdiffse', "Explicit Prejudice x Ingroup Difference (BW - WB)", `epingroupdiff', "Explicit Prejudice x Ingroup Difference SE (BW - WB)", `epingroupdiffse') append

restore

* TableS2.3, main analysis, keeping those who failed both screeners

regress offer_fairness T_bP_wR T_wP_bR T_bP_bR i.offer_amount i.round,	robust cluster(pid)

//BW - WB difference: 
lincom T_bP_wR - T_wP_bR
local ingroupdiff = r(estimate)
local ingroupdiffse = r(se)

outreg using output/TableS2.3_Study2_Fairness_NoComprehensionFilter.out, se bracket rdec(3) adec(3)3aster addstat("Ingroup Difference (BW - WB)", `ingroupdiff', "Ingroup Difference SE (BW - WB)", `ingroupdiffse') addnote("OLS coefficients with robust standard errors in brackets, clustered at respondent level.") replace

regress offer_fairness T_bP_wR T_wP_bR T_bP_bR R_symbolbinary_bw R_symbolbinary_wb R_symbolbinary_bb symbolic_binary i.offer_amount i.round, robust cluster(pid)

// BW - WB differences
lincom T_bP_wR - T_wP_bR
local ingroupdiff = r(estimate)
local ingroupdiffse = r(se)
lincom R_symbolbinary_bw - R_symbolbinary_wb
local rringroupdiff = r(estimate)
local rringroupdiffse = r(se)

outreg using output/TableS2.3_Study2_Fairness_NoComprehensionFilter.out, se bracket rdec(3) adec(3)3aster addstat("Ingroup Difference (BW - WB)", `ingroupdiff', "Ingroup Difference SE (BW - WB)", `ingroupdiffse',"Racial Resentment x Ingroup Difference (BW - WB)", `rringroupdiff', "Racial Resentment x Ingroup Difference SE (BW - WB)", `rringroupdiffse') append

regress offer_fairness T_bP_wR T_wP_bR T_bP_bR R_Explicitbinary_bw R_Explicitbinary_wb R_Explicitbinary_bb overt_binary i.offer_amount i.round, robust cluster(pid)

// BW - WB differences
lincom T_bP_wR - T_wP_bR
local ingroupdiff = r(estimate)
local ingroupdiffse = r(se)
lincom R_Explicitbinary_bw - R_Explicitbinary_wb
local epingroupdiff = r(estimate)
local epingroupdiffse = r(se)

outreg using output/TableS2.3_Study2_Fairness_NoComprehensionFilter.out, se bracket rdec(3) adec(3)3aster addstat("Ingroup Difference (BW - WB)", `ingroupdiff', "Ingroup Difference SE (BW - WB)", `ingroupdiffse',"Explicit Prejudice x Ingroup Difference (BW - WB)", `epingroupdiff', "Explicit Prejudice x Ingroup Difference SE (BW - WB)", `epingroupdiffse') append

regress offer_fairness T_bP_wR T_wP_bR T_bP_bR R_symbolbinary_bw R_symbolbinary_wb R_symbolbinary_bb R_Explicitbinary_bw R_Explicitbinary_wb R_Explicitbinary_bb symbolic_binary overt_binary i.offer_amount i.round, robust cluster(pid)

// BW - WB differences
lincom T_bP_wR - T_wP_bR
local ingroupdiff = r(estimate)
local ingroupdiffse = r(se)
lincom R_symbolbinary_bw - R_symbolbinary_wb
local rringroupdiff = r(estimate)
local rringroupdiffse = r(se)
lincom R_Explicitbinary_bw - R_Explicitbinary_wb
local epingroupdiff = r(estimate)
local epingroupdiffse = r(se)
	
outreg using output/TableS2.3_Study2_Fairness_NoComprehensionFilter.out, se bracket rdec(3) adec(3)3aster addstat("Ingroup Difference (BW - WB)", `ingroupdiff', "Ingroup Difference SE (BW - WB)", `ingroupdiffse', "Racial Resentment x Ingroup Difference (BW - WB)", `rringroupdiff', "Racial Resentment x Ingroup Difference SE (BW - WB)", `rringroupdiffse', "Explicit Prejudice x Ingroup Difference (BW - WB)", `epingroupdiff', "Explicit Prejudice x Ingroup Difference SE (BW - WB)", `epingroupdiffse') append


* TableS2.4, main analysis tobit version, eliminating those who failed both screeners

preserve

drop if failtwo == 1

tobit offer_fairness T_bP_wR T_wP_bR T_bP_bR i.offer_amount i.round, ll(0) ul(100)

//BW - WB difference: 
lincom T_bP_wR - T_wP_bR
local ingroupdiff = r(estimate)
local ingroupdiffse = r(se)

outreg using output/TableS2.4_Study2_Fairness_Tobit.out, se bracket rdec(3) adec(3)3aster addstat("Ingroup Difference (BW - WB)", `ingroupdiff', "Ingroup Difference SE (BW - WB)", `ingroupdiffse') addnote("OLS coefficients with robust standard errors in brackets, clustered at respondent level.") replace

tobit offer_fairness T_bP_wR T_wP_bR T_bP_bR R_symbolbinary_bw R_symbolbinary_wb R_symbolbinary_bb symbolic_binary i.offer_amount i.round, ll(0) ul(100)

// BW - WB differences
lincom T_bP_wR - T_wP_bR
local ingroupdiff = r(estimate)
local ingroupdiffse = r(se)
lincom R_symbolbinary_bw - R_symbolbinary_wb
local rringroupdiff = r(estimate)
local rringroupdiffse = r(se)

outreg using output/TableS2.4_Study2_Fairness_Tobit.out, se bracket rdec(3) adec(3)3aster addstat("Ingroup Difference (BW - WB)", `ingroupdiff', "Ingroup Difference SE (BW - WB)", `ingroupdiffse',"Racial Resentment x Ingroup Difference (BW - WB)", `rringroupdiff', "Racial Resentment x Ingroup Difference SE (BW - WB)", `rringroupdiffse') append

tobit offer_fairness T_bP_wR T_wP_bR T_bP_bR R_Explicitbinary_bw R_Explicitbinary_wb R_Explicitbinary_bb overt_binary i.offer_amount i.round, ll(0) ul(100)

// BW - WB differences
lincom T_bP_wR - T_wP_bR
local ingroupdiff = r(estimate)
local ingroupdiffse = r(se)
lincom R_Explicitbinary_bw - R_Explicitbinary_wb
local epingroupdiff = r(estimate)
local epingroupdiffse = r(se)

outreg using output/TableS2.4_Study2_Fairness_Tobit.out, se bracket rdec(3) adec(3)3aster addstat("Ingroup Difference (BW - WB)", `ingroupdiff', "Ingroup Difference SE (BW - WB)", `ingroupdiffse',"Explicit Prejudice x Ingroup Difference (BW - WB)", `epingroupdiff', "Explicit Prejudice x Ingroup Difference SE (BW - WB)", `epingroupdiffse') append

tobit offer_fairness T_bP_wR T_wP_bR T_bP_bR R_symbolbinary_bw R_symbolbinary_wb R_symbolbinary_bb R_Explicitbinary_bw R_Explicitbinary_wb R_Explicitbinary_bb symbolic_binary overt_binary i.offer_amount i.round, ll(0) ul(100)

// BW - WB differences
lincom T_bP_wR - T_wP_bR
local ingroupdiff = r(estimate)
local ingroupdiffse = r(se)
lincom R_symbolbinary_bw - R_symbolbinary_wb
local rringroupdiff = r(estimate)
local rringroupdiffse = r(se)
lincom R_Explicitbinary_bw - R_Explicitbinary_wb
local epingroupdiff = r(estimate)
local epingroupdiffse = r(se)
	
outreg using output/TableS2.4_Study2_Fairness_Tobit.out, se bracket rdec(3) adec(3)3aster addstat("Ingroup Difference (BW - WB)", `ingroupdiff', "Ingroup Difference SE (BW - WB)", `ingroupdiffse', "Racial Resentment x Ingroup Difference (BW - WB)", `rringroupdiff', "Racial Resentment x Ingroup Difference SE (BW - WB)", `rringroupdiffse', "Explicit Prejudice x Ingroup Difference (BW - WB)", `epingroupdiff', "Explicit Prejudice x Ingroup Difference SE (BW - WB)", `epingroupdiffse') append

restore
